package com.ruoyi.gateway.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.gateway.domain.TopicMap;
import com.ruoyi.gateway.service.ITopicMapService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 主题映射Controller
 *
 * @author 白向阳
 * @date 2025-09-28
 */
@RestController
@RequestMapping("/gateway/topic")
public class TopicMapController extends BaseController
{
    @Autowired
    private ITopicMapService topicMapService;

    /**
     * 查询主题映射列表
     */
    @PreAuthorize("@ss.hasPermi('gateway:topic:list')")
    @GetMapping("/list")
    public TableDataInfo list(TopicMap topicMap)
    {
        startPage();
        List<TopicMap> list = topicMapService.selectTopicMapList(topicMap);
        return getDataTable(list);
    }

    /**
     * 导出主题映射列表
     */
    @PreAuthorize("@ss.hasPermi('gateway:topic:export')")
    @Log(title = "主题映射", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TopicMap topicMap)
    {
        List<TopicMap> list = topicMapService.selectTopicMapList(topicMap);
        ExcelUtil<TopicMap> util = new ExcelUtil<TopicMap>(TopicMap.class);
        util.exportExcel(response, list, "主题映射数据");
    }

    /**
     * 获取主题映射详细信息
     */
    @PreAuthorize("@ss.hasPermi('gateway:topic:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(topicMapService.selectTopicMapById(id));
    }

    /**
     * 新增主题映射
     */
    @PreAuthorize("@ss.hasPermi('gateway:topic:add')")
    @Log(title = "主题映射", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TopicMap topicMap)
    {
        return toAjax(topicMapService.insertTopicMap(topicMap));
    }

    /**
     * 修改主题映射
     */
    @PreAuthorize("@ss.hasPermi('gateway:topic:edit')")
    @Log(title = "主题映射", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TopicMap topicMap)
    {
        return toAjax(topicMapService.updateTopicMap(topicMap));
    }

    /**
     * 删除主题映射
     */
    @PreAuthorize("@ss.hasPermi('gateway:topic:remove')")
    @Log(title = "主题映射", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(topicMapService.deleteTopicMapByIds(ids));
    }
}
